package com.pango.core.paginator.json;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.pango.core.easyui.json.ResultMessage;

/**
 * @author thierry.fu
 */
@SuppressWarnings("rawtypes")
public class ResultMessageJsonSerializer extends JsonSerializer<ResultMessage> {
    @SuppressWarnings("unchecked")
	@Override
    public void serialize(ResultMessage value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException {
        Map<String,Object> map = new HashMap<String, Object>();
        map.put("attributes", value.getAttributes());
        map.put("obj", value.getObj());
        map.put("success" , value.isSuccess());
        map.put("jsonStr" , value.getJsonStr());
        map.put("msg", value.getMsg());
        ObjectMapper mapper = new ObjectMapper();
        mapper.writeValue(jgen, map);
    }
}
